<?php
	function displayEcontact($pageContext, $etype) {
		if(isset($pageContext->loginUser['econtact'][$etype])) {
			echo $pageContext->loginUser['econtact'][$etype];
		}
	} 
?>
<div class="block_white">
	<div class="block_heading_black">
		<h2>Thông tin & bạn bè | Bình luận</h2>
	</div>
	
	<div class="form_register">
		<?php 
		if (isset($this->message)) {
			echo '<div style="color:red">'.$this->message.'</div>';
		}
		?>
		<?php
		    $updateAvatarUrl = array(
		        Lua_Constant_General::PARAM_CONTROLLER => "user",
		        Lua_Constant_General::PARAM_ACTION => "updateAvatar"
		    );
		    $deleteFriendUrl = array(
		        Lua_Constant_General::PARAM_CONTROLLER => "user",
		        Lua_Constant_General::PARAM_ACTION => "deleteFriend",
		    );
		?>
		<form action="<?php echo $this->url($updateAvatarUrl);?>" method="post" id = "form_upload_avatar" enctype="multipart/form-data">
			<p>
				<div class="fix08">
					<div class="txt02 fl">Ảnh đại diện</div>
					<div class="fl">
					<?php 
						if (isset($this->loginUser['avatar_photo'])) {
							echo '<img src="'.$this->loginUser['avatar_photo'].'" width="90px" height="90px"/>';
						} else {
							echo 'Chưa cập nhật';
						}
					?>
					</div>
				</div>
				<?php if (isset($this->errors['avatar']['UPLOAD_FAILED'])) { ?>
					<div class="txt04 error_msg">Upload không thành công</div>
				<?php } ?>
				<?php if (isset($this->errors['avatar']['MAX_FILE_SIZE_EXEED'])) { ?>
					<div class="txt04 error_msg">Kích thước file vượt quá 1MB</div>
				<?php } ?>
				<?php if (isset($this->errors['avatar']['INVALID_FILE_TYPE'])) { ?>
					<div class="txt04 error_msg">Chỉ hỗ trợ định dạng file jpg, png, gif, bmp.</div>
				<?php } ?>
				<div class="fix08">
					<div class="txt02 fl">Upload ảnh đại diện</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="avatar" type="file" class="textfield"/>
						</div>
					</div>
					<div class="sp_txt">(Tốt nhất ở 90x90px)</div>
				</div>
			</p>
			<p>
				<div class="fix09">
					<div class="button_gray fl">
						<a href="javascript:;" id="btnUploadAvatar">Lưu </a>
					</div>
				</div>
			</p>
		
			<p>
				<div class="fix09">
				------------------------------------------------------------------------------------
				</div>
			</p>
		</form>
		<?php
		    $updateContactUrl = array(
		        Lua_Constant_General::PARAM_CONTROLLER => "user",
		        Lua_Constant_General::PARAM_ACTION => "updateContact"
		    );
		?>
		<form action="<?php echo $this->url($updateContactUrl);?>" method="post" id = "form_update_contact">
			<p>
				<div class="fix09">
				THÔNG TIN LIÊN HỆ
				</div>
			</p>
			<p>
				<div class="fix08">
					<div class="txt02 fl">Giới thiệu ngắn gọn:</div>
`					<div class="fl">
						<textarea name="self_introduce" id ="self_introduce" ><?php
							if(isset($this->loginUser['self_introduce'])) {
								echo $this->loginUser['self_introduce'];
							} 
						?></textarea>
					</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">Địa chỉ</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">Thư điện tử</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="email" id = "email" type="text" class="textfield" value="<?php displayEcontact($this, 'EMAIL');?>"/>
						</div>
					</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">Facebook</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="facebook" id = "facebook" type="text" class="textfield" value="<?php displayEcontact($this, 'FACEBOOK');?>"/>
						</div>
					</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">Tiwtter</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="tiwtter" id = "tiwtter" type="text" class="textfield" value="<?php displayEcontact($this, 'TIWTTER');?>"/>
						</div>
					</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">Yahoo</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="yahoo" id = "yahoo" type="text" class="textfield" value="<?php displayEcontact($this, 'YAHOO');?>" />
						</div>
					</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">Skype</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="skype" id = "skype" type="text" class="textfield" value="<?php displayEcontact($this, 'SKYPE');?>" />
						</div>
					</div>
				</div>
				<div class="fix08">
					<div class="txt02 fl">G+</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="gplus" id = "gplus" type="text" class="textfield" value="<?php displayEcontact($this, 'GPLUS');?>" />
						</div>
					</div>
				</div>

			</p>
			<p>
				<div class="fix09">
					<div class="button_gray fl">
						<a href="javascript:;" id="btnSaveContact">Lưu </a>
					</div>
				</div>
			</p>

			<p>
				<div class="fix09">
				------------------------------------------------------------------------------------
				</div>
			</p>
		</form>
		<?php
		    $manageFriendUrl = array(
		        Lua_Constant_General::PARAM_CONTROLLER => "user",
		        Lua_Constant_General::PARAM_ACTION => "manageFriend"
		    );
		?>
		<form action="<?php echo $this->url($manageFriendUrl);?>" method="post" id = "form_manage_friends">
			<p>
				<div class="fix09">
				QUẢN LÝ BẠN BÈ <a style="color:green" href="javascript:alert('Nhớ thêm chức năng này nha None.');">(Thêm mới)</a><br />
				</div>
			</p>
			<p>
				<div class="fix09">
				<?php
					if (sizeof($this->friends) == 0) {
						echo 'Chưa kết nối bất cứ ai.<br />';
					}
					foreach ($this->friends as $friend) {
						if (isset($friend['avatar_photo'])) {
							echo '<img width = "45px" height="45px" src="'.$friend['avatar_photo'].'">';
						} else {
							echo $friend['username'];
						}
						echo '<a style="color:green" href="'.$this->url($deleteFriendUrl).'&fId='.$friend['id'].'">(Delete)</a><br />';
					}
				?>
				</div>
			</p>
			<p>
				<div class="fix09">
				------------------------------------------------------------------------------------
				</div>
			</p>
			<p>
				<div class="fix09">
				QUẢN LÝ TÀI KHOẢN
				</div>
			</p>
		</form>
		<?php
		    $changePassUrl = array(
		        Lua_Constant_General::PARAM_CONTROLLER => "user",
		        Lua_Constant_General::PARAM_ACTION => "changePass"
		    );
		?>
		<form action="<?php echo $this->url($changePassUrl);?>" method="post" id = "form_change_password">
			<p>
				<div class="fix08">
					<div class="txt02 fl">Đổi mật khẩu</div>
				</div>
				
				<div class="fix08">
					<div class="txt02 fl">Mật khẩu cũ</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="password" id = "password" type="password" class="textfield required" />
						</div>
					</div>
					<?php if (isset($this->errors['password'])) { ?>
					<div class="txt02 fl">&nbsp;</div>
					<div class="fl error_msg">
							Mật khẩu cũ không đúng
					</div>
					<?php } ?>
				</div>
				
				<div class="fix08">
					<div class="txt02 fl">Mật khẩu mới</div>
					<div class="fl">
						<div class="fix_textfield">
							<input name="new_password" id = "new_password" type="password" class="textfield required" />
						</div>
					</div>
					<?php if (isset($this->errors['new_password'])) { ?>
					<div class="txt02 fl">&nbsp;</div>
					<div class="fl error_msg">
							Mật khẩu mới không hợp lệ
					</div>
					<?php } ?>
				</div>

			</p>
			<p>
				<div class="fix09">
					<div class="button_gray fl">
						<a href="javascript:;" id="btnUpdatePassword">Lưu </a>
					</div>
				</div>
			</p>
		</form>	
	</div>
</div>